package com.whisper.application.service.controller;

import com.whisper.application.service.domain.VrArt;
import com.whisper.application.service.service.IVrArtService;
import com.whisper.common.annotation.Log;
import com.whisper.common.annotation.PageQuery;
import com.whisper.common.core.controller.BaseController;
import com.whisper.common.enums.BusinessType;
import com.whisper.common.excel.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文章Controller
 * 
 * @author whisper
 * @date 2024-01-07
 */
@RestController
@RequestMapping("/service/art")
public class VrArtController extends BaseController
{
    @Autowired
    private IVrArtService vrArtService;

    /**
     * 查询文章列表
     */
    @PageQuery
    @PreAuthorize("@ss.hasPermi('service:art:list')")
    @GetMapping("/list")
    public List<VrArt> list(VrArt vrArt)
    {
        return vrArtService.selectVrArtList(vrArt);
    }

    /**
     * 导出文章列表
     */
    @PreAuthorize("@ss.hasPermi('service:art:export')")
    @Log(title = "文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VrArt vrArt)
    {
        List<VrArt> list = vrArtService.selectVrArtList(vrArt);
        ExcelUtil<VrArt> util = new ExcelUtil<VrArt>(VrArt.class);
        util.exportExcel(response, list, "文章数据");
    }

    /**
     * 获取文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:art:query')")
    @GetMapping(value = "/{id}")
    public VrArt getInfo(@PathVariable("id") Long id)
    {
        return vrArtService.selectVrArtById(id);
    }

    /**
     * 新增文章
     */
    @PreAuthorize("@ss.hasPermi('service:art:add')")
    @Log(title = "文章", businessType = BusinessType.INSERT)
    @PostMapping
    public void add(@RequestBody VrArt vrArt)
    {
        vrArtService.insertVrArt(vrArt);
    }

    /**
     * 修改文章
     */
    @PreAuthorize("@ss.hasPermi('service:art:edit')")
    @Log(title = "文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public void edit(@RequestBody VrArt vrArt)
    {
        vrArtService.updateVrArt(vrArt);
    }

    /**
     * 删除文章
     */
    @PreAuthorize("@ss.hasPermi('service:art:remove')")
    @Log(title = "文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public void remove(@PathVariable Long[] ids)
    {
        vrArtService.deleteVrArtByIds(ids);
    }
}
